package web

import (
	"github.com/kataras/iris/v12"
	"iris_blog/utils"
)

type Tag struct {
}

// 首页的分页列表
func (a Tag) GetAll(i iris.Context) {
	results := []map[string]interface{}{}
	utils.DB.Raw("select * from tag ").Find(&results)
	i.JSON(map[string]interface{}{
		"code": 20000,
		"data": results,
	})

}

// 通过 tag 查询文章
func (t Tag) GetTagArticle(i iris.Context)  {

	id := i.URLParam("id")
	result := []map[string]interface{}{}
	utils.DB.Raw("SELECT * FROM article WHERE id IN (SELECT article_id FROM tag_article AS t WHERE t.tag_id = ?)",id).Find(&result)

	i.JSON(map[string]interface{}{
		"code": 20000,
		"data": result,
	})

}